package com.and.main;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import com.and.constant.Constant;
import com.and.ui.FriendList;
import com.and.ui.LoginUI;

/**
 * 
 * @ClassName: AndroidFriend
 * @Description: 作为主页面首先判断是否自动登录
 * @author hanchunping
 * @date 2010-7-5 下午04:53:24
 *
 */
public class AndroidFriend extends Activity {
	/** Called when the activity is first created. */
	private ProgressDialog mProgressDialog;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.expert);
		showDialog(Constant.DIALOG_PROCESS);
		new Thread(){
			public void run(){
				try{
					Thread.sleep(5000);
					loadSystem();
				}catch(Exception e){
					e.printStackTrace();
				}
				mProgressDialog.dismiss();
			}
		}.start();

	}
	/**
	 * 重写对话框
	 */
	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case Constant.DIALOG_PROCESS:
			mProgressDialog = new ProgressDialog(AndroidFriend.this);
			mProgressDialog.setIcon(R.drawable.stat_happy);
			mProgressDialog.setTitle("自动登录系统");
			mProgressDialog.setMessage(getString(R.string.loading));
			mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
			mProgressDialog.setIndeterminate(true);
			return mProgressDialog;
		}
		return null;
	}
	/***
	 * 
	 * @Title: loadSystem
	 * @Description: 判断加载哪个界面
	 */
	private void loadSystem(){
		SharedPreferences sp = getSharedPreferences(Constant.ACCOUNT_FILE, 0);
		Boolean bl = sp.getBoolean(Constant.ISLOGINAUTO, false);
		//自动登录
		if(bl){
			Intent i = new Intent(AndroidFriend.this,FriendList.class);
			startActivity(i);
		}else{//跳到登陆页面
			Intent i = new Intent(AndroidFriend.this,LoginUI.class);
			startActivity(i);
		}
		finish();
	}
}
	